<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户信息</title>
    <script src="${pageContext.request.contextPath}/static/js/jquery-3.3.1.js"></script>
</head>
<body>
<input id="name" type="text" value="${name}">
<input type="button" value="查询" onclick='document.location.href="?page=1" + ($("#name").val() === "" ? "" : "&name=" + $("#name").val())'>

<table border="5px">
    <caption>用户信息表</caption>

    <tr align="center">
        <th>编号</th>
        <th>用户名</th>
        <th>密码</th>
        <th>操作</th>
    </tr>
    <c:choose>
        <c:when test="${pb.totalPage < 1}">
</table>
<p>无数据</p>
        </c:when>
        <c:otherwise>
            <c:forEach var="user" items="${pb.list}">
                <tr align="center">
                    <td>${user.id}</td>
                    <td>${user.username}</td>
                    <td><input type="text" id="pwd${user.id}" value="${user.password}"></td>
                    <td>
                        <a href="JavaScript:" onclick='document.location.href="update?id=${user.id}&password=" + $("#pwd${user.id}").val()'>修改</a>
                        <a href="delete?id=${user.id}">删除</a>
                    </td>
                </tr>
            </c:forEach>
            </table>
            <a>${pb.pageIndex}/${pb.totalPage}</a>
            <a <c:if test="${pb.pageIndex != 1}">href="?page=1<c:if test="${name != null}">&name=${name}</c:if>"</c:if>>首页</a>
            <a <c:if test="${pb.pageIndex > 1}">href="?page=${pb.pageIndex - 1}<c:if test="${name != null}">&name=${name}</c:if>"</c:if>>上一页</a>
            <c:forEach begin="${1}" end="${pb.totalPage}" varStatus="in">
                <a <c:if test="${in.index != pb.pageIndex}">href="?page=${in.index}<c:if test="${name != null}">&name=${name}</c:if>"</c:if>>${in.index}</a>
            </c:forEach>
            <a <c:if test="${pb.pageIndex < pb.totalPage}">href="?page=${pb.pageIndex + 1}<c:if test="${name != null}">&name=${name}</c:if>"</c:if>>下一页</a>
            <a <c:if test="${pb.pageIndex != pb.totalPage}">href="?page=${pb.totalPage}<c:if test="${name != null}">&name=${name}</c:if>"</c:if>>尾页</a>
        </c:otherwise>
    </c:choose>
    <table border="5px">
        <caption>新增信息</caption>

        <tr align="center">
            <th>用户名</th>
            <th>密码</th>
            <th>操作</th>
        </tr>
        <tr align="center">
            <td><input type="text" id="un"></td>
            <td><input type="text" id="pwd"></td>
            <td>
                <a href="JavaScript:" onclick='document.location.href="insert?username=" + $("#un").val() + "&password=" + $("#pwd").val()'>新增</a>
            </td>
        </tr>
    </table>


</body>

</html>
